package org.yray.io.webflux.webflux;

import com.sun.net.httpserver.HttpServer;
import org.springframework.http.MediaType;
import org.springframework.http.server.reactive.HttpHandler;
import org.springframework.web.reactive.function.server.RequestPredicates;
import org.springframework.web.reactive.function.server.RouterFunctions;

import java.io.IOException;
import java.net.InetSocketAddress;

import static org.springframework.web.reactive.function.server.RequestPredicates.accept;

public class FunctionRouteApplication {
    public static void main(String[] args) throws IOException {

        HttpHandler httpHandler = RouterFunctions.toHttpHandler(
                RouterFunctions.route(RequestPredicates.POST("/selectStudent").and(accept(MediaType.APPLICATION_JSON_UTF8)), StudentHandler::selectStudent).
                        and(RouterFunctions.route(RequestPredicates.GET("/saveStudent"), StudentHandler::insertStudent)));
        HttpServer.create(new InetSocketAddress(9091),9091).createContext("");
        System.in.read();
    }
}
